package cn.com.base;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Controller;

/**
 * 名称：DmController.java<br>
 * 类描述: 共通基类<br>
 * 
 * @date 2013/05/13
 * @author ChenKai
 * 
 */
@Controller
public class DmController implements ApplicationContextAware, DisposableBean {

	/**
	 * 默认10条
	 */
	protected static final int DEFAULT_PAGE_SIZE = 10;

	/**
	 * 我的任务20条
	 */
	protected static final int USER_TASK_PAGE_SIZE = 20;

	/**
	 * 分页对象
	 */
	protected static final String REQUEST_PAGER_LIST = "pager";

	/**
	 * 时间格式: yyyy-MM-dd HH:mm:ss
	 */
	protected static final String DATE_FORMAT_01 = "yyyy-MM-dd HH:mm:ss";

	/**
	 * 选择列表(1: 表示选中首页; 2: 表示选中任务)
	 */
	protected static final String[] SELECT_ITEM_ARRAY = { "1", "2" };

	/**
	 * 论坛地址
	 */
	protected static final String BBS_IP_URL = "BBS_IP_URL";

	/**
	 * BBS地址
	 */
	protected static final String APPLICATION_BBS_URL = "BBS_URL";

	/**
	 * 前台用户登出
	 */
	protected static final String SESSION_USER_LOGOFF_KEY = "USER_LOGOFF_KEY";

	/**
	 * 前台用户登录
	 */
	protected static final String SESSION_USER_LOGIN_KEY = "USER_LOGIN_KEY";

	/**
	 * NewNotice Session Key
	 */
	protected static final String SESSION_NEW_NOTICE_KEY = "newNoticeKey";

	// 上下文
	private static ApplicationContext applicationContext = null;

	public static ApplicationContext getApplicationContext() {
		return applicationContext;
	}

	public void setApplicationContext(ApplicationContext applicationContext) {
		DmController.applicationContext = applicationContext;
	}

	public void destroy() throws Exception {
		DmController.clearHolder();
	}

	public static void clearHolder() {
		applicationContext = null;
	}

	/**
	 * 获取提示信息
	 * 
	 * @param id
	 * @return
	 */
	// protected ComMessage getMessage(String id) {
	// return getMessage(id, null);
	// }

	/**
	 * 获取提示信息
	 * 
	 * @param id
	 *            消息编号
	 * @param par
	 *            消息参数
	 * @return 消息实体
	 */
	// protected ComMessage getMessage(String id, String par[]) {
	//
	// if (id == null || id.length() <= 0) {
	// return null;
	// }
	// if (applicationContext == null) {
	// return null;
	// }
	// ComMessage msg = new ComMessage();
	// msg.setId(id);
	// msg.setMsg(applicationContext.getMessage(id, par, Locale.getDefault()));
	//
	// return msg;
	// }

	/**
	 * 获取分页信息
	 * 
	 * @param request
	 *            HttpServletRequest
	 * @return 分页信息
	 */
	/*
	 * protected Pager getPages(HttpServletRequest request) { Pager pager = new
	 * Pager(); if (request.getParameter("pageSize") != null) {
	 * pager.setPageSize(Integer.parseInt(request.getParameter("pageSize"))); }
	 * if (pager.getPageSize() == 0) { pager.setPageSize(DEFAULT_PAGE_SIZE); }
	 * if (request.getParameter("currentPage") != null) {
	 * pager.setPageNo(Integer.parseInt(request .getParameter("currentPage")));
	 * } if (pager.getPageNo() == 0) { pager.setPageNo(1); } return pager; }
	 */

	/**
	 * 获取用户会话信息
	 * 
	 * @param request
	 *            HttpServletRequest
	 * @return 用户基本信息
	 */
	// protected TalAccount getUserSession(HttpServletRequest request) {
	//
	// TalAccount talAccount = (TalAccount) request.getSession().getAttribute(
	// DictionaryType.SESSION_USER);
	// if (talAccount == null) {
	// return null;
	// }
	// return talAccount;
	// }

	/**
	 * 异常处理
	 * 
	 * @return 返回到异常画面
	 */
	/*
	 * protected ModelAndView exception() { Map<String, Object> resultMap = new
	 * HashMap<String, Object>(); resultMap.put("msg",
	 * getMessage("COM.ERROR.E0001")); return new
	 * ModelAndView(Utility.ACTION_ERROR, resultMap); }
	 */
}
